package android.cs2340UDT;
import java.util.*;

public class ToDoList{

	public String name;
	
	public ArrayList<Item> aList;
	
	public String sortString;
	
	public int sortDate;
	
	/**
	 * Constructor. Creates a new array list
	 */
	public ToDoList(String name){
		this.name = name;
		aList = new ArrayList<Item>();	
		sortString = "All Items";
		sortDate = 00000000;
	}
	
	/**
	 * Method adds an item to the list
	 * 
	 * @param item
	 */
	public void addItem(Item item){
		aList.add(item);
	}
	
	/**
	 * Creates a new item to add to the item list.
	 * 
	 * @param description The description of the item.
	 * @param location The location of the item.
	 * @param month The month an item is due.
	 * @param day The day an item is due.
	 * @param hour The hour an item is due.
	 * @param comment Reminding the user what the item is.
	 */
	public void createItem(String description, String location, String dueDate, String comment)
	{
		Item theItem = new Item(description, location, dueDate, comment);
		addItem(theItem);
	}
	/**
	 * Method returns the list
	 * 
	 * @return aList
	 */
	public ArrayList<Item> getList(){
		return aList;
	}
	/**
	 * Getter for the name of the item.
	 * 
	 * @return The name of the item.
	 */
	public String getName() {
		return name;
	}
	/**
	 * Returns a list of uncompleted items.
	 * 
	 * @param aList The list to go through.
	 * 
	 * @return A list of uncompleted items
	 */
	public ArrayList<Item> showUnComplete() {
		ArrayList<Item> temp = new ArrayList<Item>();
		for (Item item : aList) {
			if (!item.getComplete()) {
				temp.add(item);
			}
		}
		return temp;
	}
	
	public ArrayList<Item> showComplete() {
		ArrayList<Item> temp = new ArrayList<Item>();
		for (Item item : aList) {
			if (item.getComplete()) {
				temp.add(item);
			}
		}
		return temp;
	}

	
	/**
	 * Method returns ArrayList based on category
	 * 
	 * @param aList, the list to sort
	 * @param cat The category sought
	 * 
	 * @return a list of the items that are of the category passed in
	 */
	public ArrayList<Item> showCategory(ArrayList<Item> aList, String cat){
		ArrayList<Item> temp = new ArrayList<Item>();
		for(Item item: aList){
			if(item.getCategory().equals(cat))
				temp.add(item);
		}
		return temp;
	}
	
	/**
	 * Method returns ArrayList based on the date
	 * 
	 * @param aList, the list to sort
	 * @param date The array of numbers to be compared
	 * @param how to modify the search, by day, month or hour
	 * 
	 * @return a list of the items that are after the date passed in
	 */
	public ArrayList<Item> showDate(int beforeOrAfter){
		ArrayList<Item> temp = new ArrayList<Item>();
		
		for(Item item : aList) {
			if(beforeOrAfter == 0) {
				if(item.getDate() <= sortDate) {
					temp.add(item);
				}
			}
			else{
				if(item.getDate() >= sortDate) {
					temp.add(item);
				}
			}
		}
		return temp;
	}
 
}
